﻿
namespace ccs
{
	//------------------------------------------------------------------------------
	//------------------------------------------------------------------------------
	inline property::property()
	{
	}
	//------------------------------------------------------------------------------
	inline property::property(char* const var)
	{
		split_assign_variant(std::string(var), boost::false_type());
	}
	//------------------------------------------------------------------------------
	inline property::property(const char var[])
	{
		split_assign_variant(std::string(var), boost::false_type());
	}
	//------------------------------------------------------------------------------
	template<typename VarType>
	inline property::property(VarType const& var)
	{
		split_assign_variant(var, raw_variant::is_comfort<VarType>());
	}
	//------------------------------------------------------------------------------
	template<typename VarType>
	inline void property::split_assign_variant(VarType const& var, boost::true_type const&)
	{
		data_.reset(ccs_new_args(raw_variant, var));
	}
	//------------------------------------------------------------------------------
	template<typename VarType>
	inline void property::split_assign_variant(VarType const& var, boost::false_type const&)
	{
		data_.reset(create_variant(var));
	}
	//------------------------------------------------------------------------------
	template<typename VarType>
	inline VarType const& property::split_query_variant(boost::true_type const&) const
	{
		return static_cast<raw_variant&>(*data_);
	}
	//------------------------------------------------------------------------------
	template<typename VarType>
	inline VarType const& property::split_query_variant(boost::false_type const&) const
	{
		return static_cast<custom_variant<VarType>&>(*data_);
	}
	//------------------------------------------------------------------------------
	template<typename VarType>
	inline property& property::operator = (VarType const& var)
	{
		new (this) property(var);
		return (*this);
	}
	//------------------------------------------------------------------------------
	template<typename VarType>
	inline property::operator VarType const&() const
	{
		return split_query_variant<VarType>(raw_variant::is_comfort<VarType>());
	}




	//------------------------------------------------------------------------------
	//------------------------------------------------------------------------------
	inline property const& property_set::get_property(std::string const& propName) const
	{
		return get_property_nested(propName).prop_;
	}
	//------------------------------------------------------------------------------
	inline property const& property_set::add_property(std::string const& propName, property const& propVar)
	{
		prop_map::_Pairib ib = props_.insert(prop_map::value_type(propName, property_nested(propVar)));
		if (!ib.second)
		{
			std::ostringstream oss;
			oss<<"已经存在属性："<<propName;
			throw std::exception(oss.str().c_str());
		}
		return ib.first->second.prop_;
	}
	////------------------------------------------------------------------------------
	//inline property const& property_set::operator[](std::string const& propName) const
	//{
	//	return get_property(propName);
	//}
	////------------------------------------------------------------------------------
	//inline property& property_set::operator[](std::string const& propName)
	//{
	//	return props_[propName];
	//}
	//------------------------------------------------------------------------------
	inline bool property_set::has(std::string const& propName)
	{
		return (props_.find(propName) != props_.end());
	}
}